import QtQuick 2.4
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import QtQuick.Window 2.3
import "Config"

Window {
    id: rootWindow
    title: qsTr("Spark Store")
    visible: true
    width: 900
    height: 610

    minimumWidth: 900
    minimumHeight: 600

    ColorShema { id: colorShema }
    Routing { id: routing }
    GlobalSettings { id: settings }
    property alias stackView: _stackView
    property string serverUrl: settings.serverUrl
    property string nowWebUrl: "store/#/flamescion/"

    LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
    LayoutMirroring.childrenInherit: true
    ColumnLayout{
        anchors.fill: parent
        spacing: 0
        TopBar {
            id: topBar
        }

        RowLayout {

            SideBar {
                id: sideBar
                Layout.fillHeight: true

                onCurrentIndexChanged: {
                    switchToListPage(currentIndex)
                }
            }

            StackView {
                id: _stackView
                Layout.fillWidth: true
                Layout.fillHeight: true
                initialItem: routing.getUrlFromName("webListPage")
                clip: true

                pushEnter: Transition {}
                pushExit: Transition {}
            }
        }
    }

    function switchToListPage(index) {
        for(var i=1; i<_stackView.depth; ++i)
        {
            _stackView.pop()
        }
        nowWebUrl = sideBar.model.get(index).page
    }

    function switchPageFromName(name,properties){
        _stackView.push(routing.getUrlFromName(name),properties)
    }

    function goBack()
    {
        if(_stackView.depth > 1)
        {
            _stackView.pop()
        }
    }
}
